package com.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class ThreadPoolExecutorConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        DelayQueue queue = new DelayQueue<>();//延迟队列 2.7*99
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(30,40,30,
                TimeUnit.SECONDS,queue
                , Executors.defaultThreadFactory(),new ThreadPoolExecutor.DiscardPolicy());
        threadPoolExecutor.prestartAllCoreThreads();
        return threadPoolExecutor;
    }
}
